package flp.problem;

import flp.Assignment;
import flp.CleaningUsage;
import flp.InboundUsage;
import flp.OutboundUsage;

/**
 * Konkretna podklasa BuildingConstraints oparta na macierzowej
 * reprezentacji ograniczeń.
 * 
 * @author qadro_
 */
public class DenseBuildingConstraints extends BuildingConstraints
{
        /**Tablica ograniczen dla konkretnych building site'ow. */
	protected InvidualBuildingSiteConstraints constraints[];

        @Override
        public String toString()
        {
            String rep = "";
            for (InvidualBuildingSiteConstraints c : constraints)
            {
                rep += String.format("%s\n", c);
            }
            return rep;
        }
        
        public DenseBuildingConstraints () {
            //nothing here
        }
        
        public DenseBuildingConstraints(InvidualBuildingSiteConstraints[] constraints) {
                this.constraints = constraints;
        }
	
	@Override
	public boolean isLegal(Assignment a)
	{
		if (a.getUsage() == null)
			return true;
		if (a.getUsage() instanceof CleaningUsage)
			return constraints[a.getBuildingSiteID()].isLetClean();
		if (a.getUsage() instanceof OutboundUsage)
			return constraints[a.getBuildingSiteID()].isLetOutboundFor(((OutboundUsage)(a.getUsage())).getTargetRiverFacilityID());
		if (a.getUsage() instanceof InboundUsage)
			return constraints[a.getBuildingSiteID()].isLetInboundFor(((InboundUsage)(a.getUsage())).getSourceRiverFacilityID());
		//never reached
		return false;
	}
        
}
